<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
	</head>
	<body>
		<input type="checkbox" id="all">全选<br></input>
		<hr />
		<input type="checkbox" class="box">电脑<br></input>
		<input type="checkbox" class="box">手机<br></input>
		<input type="checkbox" class="box">空调<br></input>
		<script>
			var all=document.getElementById('all');
			var box=document.getElementsByClassName('box');
			all.onclick=function(){
				for (var i=0;i<box.length;i++) {
					//box[i].checked=all.checked;
					
					box[i].checked=event.target.checked;
				}
			};
		</script>
	</body>
</html>
